﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk.Client;
using DataFlock.CRM.Engine.Common;
using Microsoft.Xrm.Sdk.Discovery;
using System.Net;

namespace DataFlock.CRM.Engine
{
    public class CRMHelper
    {
        public static void Initialize()
        {
            Security.SetCredentials(string.Empty, string.Empty);
            Organization.SetDefaultOrganization();
        }
        public static void Initialize(string organizationName)
        {
            Initialize(string.Empty, string.Empty, string.Empty, organizationName);
        }

        public static void Initialize(string username, string password, string organizationName)
        {
            Initialize(username, password, string.Empty, organizationName);
        }

        public static void Initialize(string username, string password, string domain, string organizationName)
        {
            Security.SetCredentials(username, password, domain);
            Organization.SetOrganization(organizationName);
        }

        public static OrganizationServiceProxy GetService()
        {
            return new OrganizationServiceProxy(Organization.OrganizationService, Organization.HomeRealmUri, Security.Credentials, Security.DeviceCredentials);
        }

        public static OrganizationServiceContext GetContext()
        {
            return new OrganizationServiceContext(Context.GetServiceProxy());
        }
    }
}
